package com.order.manager.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.order.manager.Model.Team;
import com.order.manager.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/team")
public class TeamController {

    @Autowired
    private TeamService teamService;

    // 新增团队成员
    @PostMapping("/add")
    public boolean addTeamMember(@RequestBody Team team) {
        return teamService.save(team);
    }

    // 根据ID删除团队成员
    @DeleteMapping("/delete/{id}")
    public boolean deleteTeamMember(@PathVariable Integer id) {
        return teamService.removeById(id);
    }

    // 修改团队成员信息
//    @PutMapping("/update")
//    public boolean updateTeamMember(@RequestBody Team team) {
//        return teamService.updateById(team);
//    }

    @PutMapping("/update/{id}")
    public boolean updateTeamMember(@PathVariable Integer id, @RequestBody Team team) {
        // 设置路径中的ID到实体对象中
        team.setTeamId(id);
        return teamService.updateById(team);
    }
    // 根据ID查询团队成员
    @GetMapping("/get/{id}")
    public Team getTeamMember(@PathVariable Integer id) {
        return teamService.getById(id);
    }

    // 查询所有团队成员
    @GetMapping("/list")
    public List<Team> listTeamMembers() {
        return teamService.list();
    }


}